package gitee.derumin.really_forge.mixin;

import gitee.derumin.really_forge.items.HammerItem;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin extends Entity {
    @Shadow public abstract ItemStack getMainHandStack();

    public LivingEntityMixin(EntityType<?> type, World world) {
        super(type, world);
    }

    @Inject(method = "disablesShield", at = @At("RETURN"), cancellable = true)
    private void applyHammer(CallbackInfoReturnable<Boolean> cir){
        if (this.getMainHandStack().getItem() instanceof HammerItem){
            cir.setReturnValue(true);
        }
    }
}